﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using ELGGAPI.Data;
using ELGGAPI.Models;

namespace ELGGAPI.DomainModels
{
    public class GamesDomainModles
    {

        public static Textclass PlayGame(int GameId)
        {
            var db = new ConELGG();
            var Game = db.My_Games.Where(t => (t.GameID == GameId)).FirstOrDefault();
            if (Game != null)
                return (new Textclass { text = Game.GamePlayURL });
            else
                return (new Textclass { text = "No game found" });

        }
        public static IEnumerable<GamesModel> GetGamesList()
        {
            var db = new ConELGG();
            var Games = db.My_Games.Select(u => new GamesModel { maxplayers = u.MaxPlayers,id = u.GameID, name = u.GameName, description = u.GameDescription, redirect_url = u.GamePlayURL, provider_id = u.GameProviderID, Active = u.IsActive }).ToList();
            return (Games);
        }
        public static Idclass AddGame(GamesModel Game)
        {
            var db = new ConELGG();
            Games game;
            if (Game.id == null || Game.id <= 0)
            {

                game = new Games { GameID = 0, GameName = Game.name, MaxPlayers = Game.maxplayers ?? 0, GameDescription = Game.description, GamePlayURL = Game.redirect_url, GameProviderID = Game.provider_id, IsActive = Game.Active };
                db.My_Games.Add(game);
            }
            else
            {
                ///TODO Write Update Query
                game = new Games { GameID = Game.id ?? 0, GameName = Game.name, MaxPlayers = Game.maxplayers ?? 0, GameDescription = Game.description, GamePlayURL = Game.redirect_url, GameProviderID = Game.provider_id, IsActive = Game.Active };
            }
            db.SaveChanges();
            return (new Idclass() { id = game.GameID });

        }
    }

}